package cn.hxzy.controller;


import cn.hutool.core.util.ObjectUtil;
import cn.hxzy.common.Result;
import cn.hxzy.entity.accreditation.TsCarCard;
import cn.hxzy.entity.accreditation.TsVehicleCertification;
import cn.hxzy.entity.accreditation.vo.CarCardVo;
import cn.hxzy.service.TsCarCardService;
import cn.hxzy.service.TsVehicleCertificationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author Kuizhi.Ma
 * @since 2023-06-25
 */
@RestController
@CrossOrigin
@RequestMapping("/tsCarCard")
public class TsCarCardController {

    @Autowired
    private TsCarCardService tsCarCardService;

    @Autowired
    private TsVehicleCertificationService tsVehicleCertificationService;

    //    新增carCard信息
    @RequestMapping("insertCarCard")
    public Result insertCarCard(@RequestBody CarCardVo carCardVo) {
        if (ObjectUtil.isEmpty(carCardVo)) {
            return Result.error().code(1).message("信息填写错误");
        }
//        获取认证编号
        TsVehicleCertification tsVehicleCertification = tsVehicleCertificationService.selectTsVehicleCertification(carCardVo.getPlateNumber());
        String authenticationId = tsVehicleCertification.getAuthenticationId();
//        创建CarCard实例
        TsCarCard tsCarCard = new TsCarCard();
//        车辆认证编号
        tsCarCard.setAuthenticationId(authenticationId);
//        主车行驶证正
        tsCarCard.setTravelCardFront(carCardVo.getTravelCardFront());
//        主车行驶证反
        tsCarCard.setTravelCardOpposite(carCardVo.getTravelCardOpposite());
//        主车道路运输证
        tsCarCard.setTransportCertificate(carCardVo.getTransportCertificate());
//        道路运输经营许可证
        tsCarCard.setTransportationBusinessLicense(carCardVo.getTransportationBusinessLicense());
//        购车合同首页
        tsCarCard.setCarPurchaseContractFirst(carCardVo.getCarPurchaseContractFirst());
//        购车合同尾页
        tsCarCard.setCarPurchaseContractEnd(carCardVo.getCarPurchaseContractEnd());
//        机动车交强险保险照片
        tsCarCard.setMotorVehicleCompulsoryInsurance(carCardVo.getMotorVehicleCompulsoryInsurance());
//        人车合照
        tsCarCard.setGroupPhoto(carCardVo.getGroupPhoto());
//        备注
        tsCarCard.setNotes(carCardVo.getNotes());

        TsCarCard tsCarCard1 = tsCarCardService.insertTsCarCard(tsCarCard);
        if (ObjectUtil.isNotEmpty(tsCarCard1)) {
            return Result.ok().code(0).data1(tsCarCard1);
        }
        return Result.error().message("信息填写错误");
    }
}

